package com.pay.payment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pay.payment.entity.Pay;
import com.pay.payment.mapper.PayMapper;
import com.pay.payment.service.IPayService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * <p>
 * 支付流水 服务实现类
 * </p>
 *
 * @author lengxingzi
 * @since 2021-12-24
 */
@Service
public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements IPayService {


    @Override
    public boolean completePay(String seqNo, Integer upStatus, Integer status) {
        QueryWrapper<Pay> queryWrapper = new QueryWrapper();
        queryWrapper.eq("seq_no", seqNo);
        queryWrapper.eq("status", upStatus);
        Pay getOrder = getOne(queryWrapper);
        getOrder.setStatus(status);
        return updateById(getOrder);
    }
    @Override
    public boolean callBackCompletePay(String seqNo, Integer upStatus, Integer status, Date date) {
        QueryWrapper<Pay> queryWrapper = new QueryWrapper();
        queryWrapper.eq("seq_no", seqNo);
        queryWrapper.eq("status", upStatus);
        Pay getOrder = getOne(queryWrapper);

        getOrder.setStatus(status);
        getOrder.setFinishedRepayTime(LocalDateTime.now());
        return updateById(getOrder);
    }
    @Override
    public boolean callBackRefundPay( String seqNo,Integer upStatus,Integer status,Date date) {
        QueryWrapper<Pay> queryWrapper = new QueryWrapper();
        queryWrapper.eq("seq_no", seqNo);
        queryWrapper.eq("status", upStatus);
        Pay getOrder = getOne(queryWrapper);
        getOrder.setStatus(status);
        getOrder.setRefundTime(LocalDateTime.now());
        return updateById(getOrder);
    }
    @Override
    public boolean callBackPay( String seqNo,Integer status) {
        QueryWrapper<Pay> queryWrapper = new QueryWrapper();
        queryWrapper.eq("seq_no", seqNo);
        Pay getOrder = getOne(queryWrapper);
        getOrder.setStatus(status);
        return updateById(getOrder);
    }

    @Override
    public boolean callBackSucceedPay( String seqNo,String referenceId,String payerVa,Integer status) {
        QueryWrapper<Pay> queryWrapper = new QueryWrapper();
        queryWrapper.eq("seq_no", seqNo);
        Pay getOrder = getOne(queryWrapper);
        getOrder.setStatus(status);
        getOrder.setReferenceId(referenceId);
        getOrder.setPayerVa(payerVa);
        return updateById(getOrder);
    }


}
